package com.tom.demo.controller.system;

import com.tom.demo.common.annotation.OperaLog;
import com.tom.demo.common.entity.SysMenu;
import com.tom.demo.common.enumeration.OperaTypeEnum;
import com.tom.demo.common.response.Result;
import com.tom.demo.service.system.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = {"菜单管理"})
@RestController
@RequestMapping(path = {"/menu"})


public class MenuController {

    @Resource
    private MenuService menuService;


    @PostMapping(path = {"/list"})
    @ApiOperation(value = "获取菜单列表")
    @PreAuthorize(value = "hasAuthority('system:menu:list')")
    public Result pageList(){
        return menuService.list();
    }


    @DeleteMapping(path = {"/deleteByMenuId/{menuId}"})
    @ApiOperation(value = "删除菜单")
    @PreAuthorize(value = "hasAuthority('system:menu:remove')")
    @OperaLog(operaModel = "菜单管理",operaType = OperaTypeEnum.DELETE,operaDesc = "删除菜单")
    public Result deleteByMenuId(@PathVariable(value = "menuId")String menuId){
        return menuService.deleteByMenuId(menuId);
    }

    @GetMapping(path = {"/optionsTree"})
    @ApiOperation(value = "获取目录下拉选项菜单")
    public Result optionsTree(@RequestParam(value = "menuType")String menuType){
        return menuService.optionsTree(menuType);
    }

    @PostMapping(path = {"/insertMenu"})
    @ApiOperation(value = "添加菜单")
    @OperaLog(operaModel = "菜单管理",operaType = OperaTypeEnum.ADD,operaDesc = "添加菜单")
    public Result insertMenu(@RequestBody SysMenu sysMenu){
        return menuService.insertMenu(sysMenu);
    }

}
